package com.dpteam.dao.impl;

import com.dpteam.dao.MemberDao;
import com.dpteam.model.Member;
import com.dpteam.util.Page;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: luolei
 * Date: 2016/1/8
 * Time: 9:02
 */
@Repository
public class MemberDaoImpl extends BaseDaoImpl<Member> implements MemberDao {

    @Override
    public List<Member> findByName(String name) {
        String hql = "from Member where name like ? order by id ";
        return find(hql, "%" + name + "%");
    }

    @Override
    public List<Member> findByNameByPage(String name, Page page) {
        String hql = "from Member where name like ? order by id ";
        return find(hql, page, "%" + name + "%");
    }

    @Override
    public Member findByPhone(String phone) {
        String hql = "from Member where phone = ?";
        return get(hql, phone);
    }

    @Override
    public Member findByIDCard(String IDCard) {
        String hql = "from Member where IDCard = ?";
        return get(hql, IDCard);
    }

    @Override
    public List<Member> findByLevel(int level) {
        String hql = "from Member where levelId = ? order by id ";
        return find(hql, level);
    }

    @Override
    public List<Member> findByLevelByPage(int level, Page page) {
        String hql = "from Member where levelId = ? order by id ";
        return find(hql, page, level);
    }

    @Override
    public List<Member> findAll() {
        String hql = "from Member order by id ";
        return find(hql);
    }

    @Override
    public List<Member> findAllByPage(Page page) {
        String hql = "from Member order by id ";
        return find(hql, page);
    }

    @Override
    public void deleteById(int id) {
        Member member = get(Member.class, id);
        if (member != null) {
            delete(member);
        }
    }
}
